//
//  FXTUserTools.m
//  OfferJob
//
//  Created by 郑州动力无限科技 on 2017/6/30.
//  Copyright © 2017年 郑州动力无限科技. All rights reserved.
//

#import "FXTUserTools.h"
#define userAccountPath @"userAccout.data"
@implementation FXTUserTools
#pragma mark - 用户登录数据处理有关

// 保存用户登录数据
+(void)saveUserAccount:(FXTUserModel*)account {
    NSString *userAccountFile = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject] stringByAppendingPathComponent:userAccountPath];
    [NSKeyedArchiver archiveRootObject:account toFile:userAccountFile];
}
// 取得用户登录数据
+(FXTUserModel *)UserAccount {
    NSString *userAccountFile = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject] stringByAppendingPathComponent:userAccountPath];
    
    FXTUserModel *userAccount = [NSKeyedUnarchiver unarchiveObjectWithFile:userAccountFile];
    return userAccount;
}
#pragma mark - 清除数据有关

// 清除所有的微信登录数据和用户自身的数据
+(void)removeAllWechatAndUserDatas {
    [self removeAllUserDatas];
}
// 清除所有用户的数据
+(void)removeAllUserDatas {
    NSString *userFile = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject] stringByAppendingPathComponent:userAccountPath];
    
    NSFileManager *defaultManager = [NSFileManager defaultManager];
    [defaultManager removeItemAtPath:userFile error:nil];
    
}
#pragma mark - 其他数据处理方面

// 是否登录过
+(BOOL)isAlreadyLogin {
    if ([self UserAccount]) {
        return YES;
    }
    return NO;
}

@end
